﻿using NPOI.SS.Util;

namespace NpoiSample.Helper.CompleteCustomer.Dto
{
    /// <summary>
    /// 合并配置
    /// </summary>
    public class MergeConfigDto
    {
        /// <summary>
        /// 合并配置
        /// </summary>
        /// <param name="endRow">结束行</param>
        /// <param name="firstCol">开始列</param>
        /// <param name="endCol">结束列</param>
        public MergeConfigDto(int endRow, int firstCol, int endCol)
        {
            EndRow = endRow;
            FirstCol = firstCol;
            EndCol = endCol;
        }

        /// <summary>
        ///合并配置
        /// </summary>
        /// <param name="mergeColNum">往后合并的列数</param>
        public MergeConfigDto(int mergeColNum)
        {
            MergeColNum = mergeColNum;
        }

        /// <summary>
        /// 结束行
        /// </summary>
        public int EndRow { get; }

        /// <summary>
        /// 开始列
        /// </summary>
        public int FirstCol { get; }

        /// <summary>
        /// 终止列
        /// </summary>
        public int EndCol { get; }

        /// <summary>
        ///要合并的列数
        /// </summary>
        public int MergeColNum { get; }

        /// <summary>
        /// 获取合并配置
        /// </summary>
        /// <param name="currRow"></param>
        /// <param name="currCol"></param>
        /// <returns></returns>
        public CellRangeAddress GetCellRangeAddress(int currRow, int currCol)
        {
            if (MergeColNum != 0)
                return new CellRangeAddress(currRow, currRow, currCol, currCol + MergeColNum - 1);

            return new CellRangeAddress(currRow, EndRow, currCol, EndCol);
        }
    }
}